import {
  getHotSearchWord
} from "../../utils/http"
Page({
  async onLoad() {
    let res = await getHotSearchWord()
    if (res.code !== 200) {
      return wx.showToast({
        title: res.msg,
        icon: 'none'
      })
    }
    this.setData({
      hotSearchWord: res.data
    })
  },
  goBack() {
    wx.navigateBack()
  },
  clickWord(e) {
    let {
      index
    } = e.currentTarget.dataset
    let word = this.data.hotSearchWord[index]
    this.searchWord = word
    this.setData({
      searchWord: word
    })
    this.search()
  },
  searchWordInput(e) {
    this.searchWord = e.detail.value
  },
  searchWordFocus() {
    this.searchWord = null
    this.setData({
      searchWord: null
    })
  },
  async search() {
    if (!this.searchWord) return
    wx.navigateTo({
      url: `/pages/music/index?type=search&id=${this.searchWord}&navtitle=${this.searchWord}`,
    })
  },
})